<template>
  <div class="page-container vehicle-accounting w-full h-full">
    <a-scrollbar
      ref="scrollbarRef"
      :outer-style="{ height: '100%', width: '100%', 'overflow-x': 'hidden' }"
      style="height: 100%; overflow-y: auto; overflow-x: hidden"
      @scroll="onScroll"
    >
      <div class="content">
        <list-searcher :searchList="searchList" v-model:searchForm="queryParam" @loadData="onSearch" class="overflow-hidden" />
        <CardWrap>
          <Card bigSize v-for="item in TotalList" :key="item.label" :color="item.color">
            <div class="flex">
              <template v-for="(child, index) in item.children" :key="child.label">
                <div class="flex flex-col w-1/2">
                  <CardCellIcon :label="child.label" :icon="child.icon" style="margin-bottom: 8px" />
                  <CardTotal :value="TotalData[child.key]" :color="item.color" />
                </div>
                <a-divider direction="vertical" :style="{ borderColor: item.borderColor }" v-if="index != item.children.length - 1" />
              </template>
            </div>
          </Card>
        </CardWrap>
        <div class="mb-5">
          <a-alert class="items-start">
            <template #icon>
              <icon-exclamation-circle />
            </template>
            <div> 1、单车核算统计车辆在运营过程中产生的收入及支出，不根据费用的结算状态统计，默认统计上月数据； </div>
            <div> 2、订单营收汇总时，根据费用的生成时间在所选月份内找到对应的订单，将订单下所有费项根据规则完成统计； </div>
            <div> 3、单车核算下所有数据每日凌晨自动更新，当天操作的数据需第二日生效。 </div>
          </a-alert>
        </div>

        <div class="flex justify-between flex-wrap mb-4">
          <div class="flex items-center">
            <div class="flex items-center">
              <div>车辆总数：</div>
              <div class="total-item-value">{{ TotalData.carTotalCount || '-' }}</div>
              <div class="ml-1">辆</div>
            </div>
            <a-divider direction="vertical" />
            <div class="flex items-center">
              <div>已盈利车辆：</div>
              <div class="total-item-value">{{ TotalData.profitCarCount || '-' }}</div>
              <div class="ml-1">辆</div>
            </div>
            <a-divider direction="vertical" />
            <div class="flex items-center">
              <div>未盈利车辆：</div>
              <div class="total-item-value">{{ TotalData.lossCarCount || '-' }}</div>
              <div class="ml-1">辆</div>
            </div>
          </div>
          <div class="flex gap-4">
            <a-button v-permission="'svms:index:revenue:vehicle-accounting.rule'" type="secondary" @click="handleRuleExplain"
              >统计规则说明</a-button
            >
            <a-button v-permission="'svms:index:revenue:vehicle-accounting.setTax'" type="secondary" @click="handleSetTax"
              >设置购置税分期</a-button
            >
            <!-- <a-button v-permission="'svms:index:revenue:vehicle-accounting.config'" type="secondary" @click="handleConfig"
              >订单保险/车损/油电费费项配置</a-button
            > -->
            <a-button v-permission="'svms:index:revenue:vehicle-accounting.report'" type="secondary" @click="handleRxport">
              单车核算统计报表
            </a-button>
            <a-button v-permission="'svms:index:revenue:vehicle-accounting.export'" type="secondary" @click="handleExport">
              列表明细导出
            </a-button>
            <a-button v-permission="'svms:index:revenue:vehicle-accounting.fold'" type="primary" @click="handleTableHeaderFold">{{
              table.isTableHeaderFold ? '一键展开表头' : '一键收起表头'
            }}</a-button>
            <a-button v-permission="'svms:index:revenue:vehicle-accounting.fold'" type="primary" @click="handleExpandAll">{{
              table.isFold ? '一键展开门店' : '一键收起门店'
            }}</a-button>
          </div>
        </div>

        <div class="last-update-time mb-4">
          <div>数据更新时间：{{ TotalData.lastUpdateTime || '-' }}</div>
        </div>

        <fold-table
          ref="foldTableRef"
          :table="table"
          :expandTable="expandTable"
          v-model:tableIsFold="table.isFold"
          v-model:tableIsTableHeaderFold="table.isTableHeaderFold"
          @loadData="loadData"
        >
          <template #profitFlagName="{ record }">
            <a-tag :color="record.profitFlag == 0 ? 'orange' : 'green'">{{ record.profitFlagName }}</a-tag>
            {{ record.totalProfitAmount }}
          </template>
          <!-- <template #totalProfitAmount="{ record }">
            <div>
              <a-tag :color="record.profitFlag == 0 ? 'orange' : 'green'" style="margin-left: 4px">{{ record.profitFlagName }}</a-tag>
              {{ record.totalProfitAmount }}
            </div>
          </template> -->
          <template #insuranceFee="{ record }">
            <div
              @click="goPremiumDetail(record)"
              :class="{
                canclick: decimal.add(record.feeInfo.businessInsureAmount || 0, record.feeInfo.compulsoryInsureAmount || 0) != 0,
              }"
            >
              {{ decimal.add(record.feeInfo.businessInsureAmount || 0, record.feeInfo.compulsoryInsureAmount || 0) }}
            </div>
          </template>
        </fold-table>
      </div>
    </a-scrollbar>
  </div>

  <!-- 费用弹框 -->
  <FeeModal ref="feeModalRef" @close="loadData" />
  <!-- 订单保险/车损/油电费费项配置 -->
  <OrderInsuranceConfigModal ref="orderInsuranceConfigModalRef" @ok="handleOrderInsuranceConfig" />
  <!-- 设置购置税分期 -->
  <SetPurchaseTaxModal ref="setPurchaseTaxModalRef" @ok="loadData" />
  <!-- 统计规则说明 -->
  <RuleExplainModal ref="ruleExplainModalRef" />
</template>
<script setup lang="ts" name="VehicleAccounting">
  import CardWrap from '../revenue-summary/components/card/card-wrap.vue'
  import Card from '../revenue-summary/components/card/index.vue'
  import CardCellIcon from '../revenue-summary/components/card/card-cell-icon.vue'
  import CardTotal from '../revenue-summary/components/card/card-total.vue'
  import FeeModal from './components/modals/fee-modal.vue'
  import OrderInsuranceConfigModal from './components/modals/order-insurance-config-modal.vue'
  import SetPurchaseTaxModal from './components/modals/set-purchase-tax-modal.vue'
  import RuleExplainModal from './components/modals/rule-explain-modal.vue'

  import decimal from '@/utils/calculation'
  import foldTable from './components/table/index.vue'
  import { useTable } from '@/hooks/table'
  import { usePageDict } from '@/hooks/useDict'
  import dayjs from 'dayjs'
  import { computed, onActivated, onMounted, reactive, ref } from 'vue'
  import { navigate2permission } from './utils'
  import useNavigate from '@/hooks/useNavigate'
  import { useExport } from '@/hooks/list'
  import {
    getsingleCarStatistics,
    exportSingleCarAccounting,
    getStatisticsData,
    getOrderRevenueTips,
    exportSingleCarAccountingReport,
  } from '@/api/dashboard/vehicleAccounting'

  const { navigateTo } = useNavigate()

  const queryParam = reactive<any>({
    accountMonth: [dayjs().add(-1, 'month').format('YYYY-MM'), dayjs().add(-1, 'month').format('YYYY-MM')],
    startTime: dayjs().add(-1, 'month').format('YYYY-MM'),
    endTime: dayjs().add(-1, 'month').format('YYYY-MM'),
  })
  const feeModalRef = ref()
  // 不计免赔
  const deductibleFeeNameEnums = ref<any[]>([])
  // 车损费
  const carDamageFeeNameEnums = ref<any[]>([])
  // 油电费
  const oilFeeNameEnums = ref<any[]>([])
  const carStatusEnums = usePageDict('carStatusDict')

  const searchList = computed(() => [
    {
      type: 'a-range-picker',
      label: '核算月份',
      prop: 'accountMonth',
      attrs: {
        mode: 'month',
        placeholder: ['开始月份', '结束月份'],
        disabledDate: (current: string) => dayjs(current).isBefore(dayjs('2024-01')),
        allowClear: false,
      },
      change: (value: any) => {
        console.log('核算月份', value)

        queryParam.startTime = value[0]
        queryParam.endTime = value[1]
      },
    },
    {
      type: 'a-input',
      label: '车牌号',
      prop: 'licenseNoLike',
    },
    {
      type: 'remote-select',
      label: '车型',
      prop: 'modelIdList',
      attrs: {
        type: 'car_model_tenantList_multiple',
      },
    },
    {
      type: 'remote-select',
      label: '车系',
      prop: 'seriesIdList',
      attrs: {
        type: 'car_series_multiple',
      },
    },
    {
      type: 'remote-select',
      label: '费用产生门店',
      prop: 'orgIdList',
      attrs: {
        type: 'org_add_listByStaff_multiple',
      },
    },
    {
      type: 'a-select',
      label: '车辆状态',
      prop: 'operateStatusList',
      options: carStatusEnums.operateStatusEnums,
      attrs: {
        multiple: true,
      },
    },
    {
      type: 'a-select',
      label: '车辆来源',
      prop: 'carSourceList',
      options: carStatusEnums.carSourceEnums,
      attrs: {
        multiple: true,
      },
    },
    {
      type: 'a-select',
      label: '盈利情况',
      prop: 'profitFlag',
      options: carStatusEnums.profitFlagEnums,
    },
  ])

  const TotalData = ref<any>({
    expectTotalProfitAmount: 0,
    actualTotalProfitAmount: 0,
    expectTotalExpenditureAmount: 0,
    actualTotalExpenditureAmount: 0,
    expectTotalRevenueAmount: 0,
    actualTotalRevenueAmount: 0,
    profitCarCount: null,
    lossCarCount: null,
    carTotalCount: null,
    lastUpdateTime: null,
  })
  const TotalList = computed(() => [
    {
      label: '总利润',
      color: 'purple',
      borderColor: '#5C37FF',
      children: [
        {
          label: '预计总利润',
          key: 'expectTotalProfitAmount',
          icon: 'income-money-v1',
          color: 'purple',
        },
        {
          label: '实际总利润',
          key: 'actualTotalProfitAmount',
          icon: 'income-money-v1',
          color: 'purple',
        },
      ],
    },
    {
      label: '总收入',
      color: 'green',
      borderColor: '#2EC350',
      children: [
        {
          label: '预计总收入',
          key: 'expectTotalRevenueAmount',
          icon: 'asset-total',
          color: 'green',
        },
        {
          label: '实际总收入',
          key: 'actualTotalRevenueAmount',
          icon: 'asset-total',
          color: 'green',
        },
      ],
    },
    {
      label: '总支出',
      color: 'orange',
      borderColor: '#FF7D00',
      children: [
        {
          label: '预计总支出',
          key: 'expectTotalExpenditureAmount',
          icon: 'expend-purchase',
          color: 'orange',
        },
        {
          label: '实际总支出',
          key: 'actualTotalExpenditureAmount',
          icon: 'expend-purchase',
          color: 'orange',
        },
      ],
    },
  ])

  // 数据统计
  const handleStatisticsData = () => {
    getStatisticsData(queryParam).then((res: any) => {
      TotalData.value = res.result
    })
  }

  // 获取订单营收提示
  const handleOrderRevenueTips = () => {
    getOrderRevenueTips({}).then((res: any) => {
      deductibleFeeNameEnums.value = res.result.deductibleFeeNameEnums.map((item: any) => item.name)
      carDamageFeeNameEnums.value = res.result.carDamageFeeNameEnums.map((item: any) => item.name)
      oilFeeNameEnums.value = res.result.oilFeeNameEnums.map((item: any) => item.name)
    })
  }

  const handleOrderInsuranceConfig = () => {
    loadData()
    handleOrderRevenueTips()
  }

  // 跳转车辆详情
  const goCarDetail = (item: any, type: string) => {
    const params: any = { carId: item.carId, from: 'car-manage', tab: 8, tabName: item.licenseNo }

    if (type == 'purchasePayAmount') {
      params.date = queryParam.accountMonth
    }

    navigate2permission('carManageDetail', params, navigateTo)
  }

  // 跳转保险费详情
  const goPremiumDetail = (item: any) => {
    if (decimal.add(item.feeInfo.businessInsureAmount || 0, item.feeInfo.compulsoryInsureAmount || 0) == 0) {
      return
    }

    const params = { carId: item.carId, from: 'car-manage', tab: 2, tabName: item.licenseNo }
    navigate2permission('carManageDetail', params, navigateTo)
  }

  // 跳转车辆处置列表
  const goDisposalList = (item: any) => {
    const params = { licenseNoLike: item.licenseNo }
    navigate2permission('carDisposalList', params, navigateTo)
  }

  // 一键展开/收起
  const foldTableRef = ref()
  const handleExpandAll = () => {
    foldTableRef.value.handleFoldClick()
  }

  const handleTableHeaderFold = () => {
    foldTableRef.value.handleTableHeaderFoldClick()
  }

  // 统计规则说明
  const ruleExplainModalRef = ref()
  const handleRuleExplain = () => {
    ruleExplainModalRef.value.open()
  }

  // 设置购置税分期
  const setPurchaseTaxModalRef = ref()
  const handleSetTax = () => {
    setPurchaseTaxModalRef.value.open()
  }

  // 订单保险配置
  const orderInsuranceConfigModalRef = ref()
  const handleConfig = () => {
    orderInsuranceConfigModalRef.value.open(carStatusEnums.tenantCostConfigTypeEnums)
  }

  // 单车核算统计报表
  const handleRxport = () => {
    useExport(exportSingleCarAccountingReport, queryParam)
  }

  // 导出
  const handleExport = () => {
    useExport(exportSingleCarAccounting, queryParam)
  }

  const expandColumns = computed(() => {
    return [
      {
        title: '费用产生门店',
        width: 150,
        dataIndex: 'orgName',
        isString: true,
        fixed: 'left',
      },
      {
        title: '预计收益',
        desc: '(含未结算)',
        width: 140,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-blue',
        children: [
          {
            title: '预计收入',
            width: 110,
            tooltipList: [
              '1、预计收入=结算状态为待结算+已结算的所有收入费项之和',
              '2、预计收入包含的费项为：订单下所有费项、车辆借出收入、车辆处置收入、违章代办总计',
            ],
            dataIndex: 'feeInfo.expectedTotalRevenueAmount',
            headerCellClass: 'table-bg-blue',
            headerCellStyle: {
              color: '#253276',
            },
          },
          {
            title: '预计支出',
            width: 110,
            tooltipList: [
              '1、预计支出=结算状态为待结算+已结算，运营成本支出付款状态为未付款+已付款所有支出费项之和',
              '2、预计支出包含的费项为： 保险费支出、保养费支出、维修费支出、年检费支出、报销单支出、付款单支出',
            ],
            dataIndex: 'feeInfo.expectedTotalExpenditureAmount',
            headerCellClass: 'table-bg-blue',
            headerCellStyle: {
              color: '#253276',
            },
          },
          {
            title: '收益总计',
            width: 110,
            tooltipList: ['预计收益总计=预计收入-预计支出'],
            dataIndex: 'feeInfo.expectedTotalProfitAmount',
            headerCellClass: 'table-bg-blue',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '实际收益',
        desc: '(全部已结算)',
        width: 140,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-purple',
        children: [
          {
            title: '实际收入',
            width: 110,
            tooltipList: [
              '1、实际收入=结算状态为已结算，运营成本支出付款状态为已付款所有收入费项之和',
              '2、实际收入包含的费项为：订单下所有费项、车辆借出收入、车辆处置收入、违章代办收入',
            ],
            dataIndex: 'feeInfo.totalRevenueAmount',
            headerCellClass: 'table-bg-purple',
            headerCellStyle: {
              color: '#3A1E4D',
            },
          },
          {
            title: '实际支出',
            width: 110,
            tooltipList: [
              '1、实际支出=结算状态为已结算，运营成本支出付款状态为已付款所有支出费项之和',
              '2、实际支出包含的费项为： 保险费支出、保养费支出、维修费支出、年检费支出、报销单支出、付款单支出',
            ],
            dataIndex: 'feeInfo.totalExpenditureAmount',
            headerCellClass: 'table-bg-purple',
            headerCellStyle: {
              color: '#3A1E4D',
            },
          },
          {
            title: '收益总计',
            width: 110,
            tooltipList: ['实际收益总计=实际收入-实际支出'],
            dataIndex: 'feeInfo.totalProfitAmount',
            headerCellClass: 'table-bg-purple',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '订单营收',
        width: 170,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-cyan',
        children: [
          {
            title: '订单收入汇总',
            width: 170,
            isParent: true,
            isChildShow: true,
            isToggle: true,
            toggleStatus: false,
            headerCellClass: 'table-bg-cyan1',
            headerCellStyle: {
              color: '#576F1A',
            },
            children: [
              {
                title: '租金收入',
                width: 110,
                tooltipList: [
                  '1、订单租金：符合筛选条件订单下的车辆租金、手续费、保险费之和，包含续租产生的车辆租金、手续费、保险费',
                  '2、如订单存在换车，则统计的金额为所选车辆在订单使用期间所产生的费用，且订单租金、保险费需平分至每一天计算，手续费则默认归换下车辆',
                  '3、保险费包含基础保险、不计免赔、保险升级以及在系统配置的用车保险费用',
                ],
                dataIndex: 'feeInfo.rentAmount',
                headerCellClass: 'table-bg-cyan1',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('租金收入', record)
                  feeModalRef.value.open(
                    {
                      orgIdList: [record.orgId],
                      startTime: queryParam.startTime,
                      endTime: queryParam.endTime,
                      carId: record.carId,
                      licenseNo: record.licenseNo,
                      feeCategory: 20,
                      profitFlag: queryParam.profitFlag,
                      isFilter: false,
                    },
                    'rentAmount'
                  )
                },
              },
              {
                title: '其他费用收入',
                width: 140,
                tooltipList: [
                  '1、订单中除车辆租金、手续费、保险费以外的剩余所有费项，都为其他费项，包含订单佣金',
                  '2、如订单存在换车，则上门送车费、夜间取车费归属添加费用时正在使用的那辆车，上门取车费、夜间还车费、同城异店还车费、跨城异店还车费归属最后还车车辆',
                ],
                dataIndex: 'feeInfo.orderOtherAmount',
                headerCellClass: 'table-bg-cyan1',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('其他费用收入2', record)
                  feeModalRef.value.open(
                    {
                      orgIdList: [record.orgId],
                      startTime: queryParam.startTime,
                      endTime: queryParam.endTime,
                      carId: record.carId,
                      licenseNo: record.licenseNo,
                      feeCategory: 21,
                      profitFlag: queryParam.profitFlag,
                      isFilter: false,
                    },
                    'otherFeeAmount'
                  )
                },
              },
              {
                title: '渠道线上费用收入',
                width: 110,
                tooltipList: ['1、渠道订单中线上费用总计', '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间所产生的线上费用'],
                dataIndex: 'feeInfo.onlineAmount',
                headerCellClass: 'table-bg-cyan1',
              },
              {
                title: '线下费用收入',
                width: 140,
                tooltipList: ['1、所有订单线下费用总计', '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间所产生的费用'],
                dataIndex: 'feeInfo.offlineAmount',
                headerCellClass: 'table-bg-cyan1',
              },
              {
                title: '收入总计',
                width: 130,
                tooltipList: [
                  '1、订单总收入为所选车辆在订单内的总收入，渠道线上费用收入+线下费用收入',
                  '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间所产生的费用',
                ],
                dataIndex: 'feeInfo.orderTotalAmount',
                headerCellClass: 'table-bg-cyan1',
              },
            ],
          },
          // {
          //   title: '订单重要费项汇总',
          //   headerCellClass: 'table-bg-cyan2',
          //   headerCellStyle: {
          //     color: '#576F1A',
          //   },
          //   children: [
          //     {
          //       title: '续租费',
          //       width: 90,
          //       dataIndex: 'feeInfo.rerentAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '基础保险',
          //       width: 90,
          //       dataIndex: 'feeInfo.orderInsureAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '不计免赔',
          //       width: 110,
          //       tooltipList: computed(() => [
          //         `不计免赔=不计免赔+保险升级+手动配置的费项之和${
          //           deductibleFeeNameEnums.value.length > 0 ? `，手动配置的费项包含：${deductibleFeeNameEnums.value.join('，')}` : ''
          //         }`,
          //       ]),
          //       dataIndex: 'feeInfo.deductibleAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '车损费',
          //       width: 100,
          //       tooltipList: computed(() => [
          //         `车损费=车损费用+配置的相关费用之和${
          //           carDamageFeeNameEnums.value.length > 0 ? `，手动配置的费项包含：${carDamageFeeNameEnums.value.join('，')}` : ''
          //         }`,
          //       ]),
          //       dataIndex: 'feeInfo.carDamageAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '油电费',
          //       width: 100,
          //       tooltipList: computed(() => [
          //         `油电费=油电费用+配置的相关费用之和${
          //           oilFeeNameEnums.value.length > 0 ? `，手动配置的费项包含：${oilFeeNameEnums.value.join('，')}` : ''
          //         }`,
          //       ]),
          //       dataIndex: 'feeInfo.oilAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //   ],
          // },
          {
            title: '违章代办收入',
            width: 140,
            tooltipList: [
              '1、违章代办总计=代办服务费-代办真实成本',
              '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间产生违章生成的代办费',
            ],
            dataIndex: 'feeInfo.violationHandleAmount',
            headerCellClass: 'table-bg-cyan',
            headerCellStyle: {
              color: '#576F1A',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('违章代办总计2', record)
              feeModalRef.value.open(
                { ...queryParam, carId: record.carId, orgIdList: [record.orgId], isFilter: false },
                'violationFeeAmount'
              )
            },
          },
          {
            title: '营收总计',
            width: 110,
            tooltipList: ['营收总计=订单总收入+违章代办总计'],
            dataIndex: 'feeInfo.orderRevenueTotalAmount',
            headerCellClass: 'table-bg-cyan',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '运营成本支出',
        width: 150,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-yellow1',
        children: [
          {
            title: '报销单支出',
            width: 130,
            tooltipList: ['1、车辆生成的报销单费用总计', '2、统计报销费用时，时间取费用明细下的费用发生时间，车辆取费用明细下关联的车辆'],
            dataIndex: 'feeInfo.costSellAmount',
            headerCellClass: 'table-bg-yellow1',
            headerCellStyle: {
              color: '#64540E',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('报销单总计2', record)
              feeModalRef.value.open(
                { ...queryParam, orgIdList: [record.orgId], carId: record.carId, feeCategory: 10, isFilter: false },
                'expenseFeeAmount'
              )
            },
          },
          {
            title: '付款单支出',
            width: 130,
            tooltipList: [
              '1、付款单中关联所选车辆的费用总计',
              '2、统计付款单费用时，时间取费用明细下的费用发生时间，车辆取费用明细下关联的车辆',
            ],
            dataIndex: 'feeInfo.costPayAmount',
            headerCellClass: 'table-bg-yellow1',
            headerCellStyle: {
              color: '#64540E',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('付款单总计2', record)
              feeModalRef.value.open(
                { ...queryParam, orgIdList: [record.orgId], carId: record.carId, feeCategory: 11, isFilter: false },
                'paymentFeeAmount'
              )
            },
          },
          {
            title: '支出总计',
            width: 110,
            tooltipList: ['支出总计=报销单总计+付款单总计'],
            dataIndex: 'feeInfo.costTotalAmount',
            headerCellClass: 'table-bg-yellow1',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '车辆运营费用',
        width: 150,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        headerCellClass: 'table-bg-red',
        align: 'center',
        children: [
          {
            title: '保险费支出',
            width: 190,
            slotName: 'insuranceFee',
            isToggle: true,
            toggleStatus: false,
            tooltipList: [
              '1、商业险、交强险会根据有效期及保险费用，精确计算到每日应付',
              '2、根据筛选条件，统计车辆商业险、交强险保费总额，每日保险金额✖️筛选的时间天数=保险费应付金额',
              '3、取保险单状态：待生效、已生效、已失效、已退保',
              '4、如保险未填写有效期，则不计算，请及时完善保险有效期信息',
            ],
            headerCellClass: 'table-bg-red',
            align: 'center',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            children: [
              {
                title: '商业险金额',
                width: 100,
                dataIndex: 'feeInfo.businessInsureAmount',
                headerCellClass: 'table-bg-red',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('商业险应付2', record)
                  goPremiumDetail(record)
                },
              },
              {
                title: '交强险金额',
                width: 100,
                dataIndex: 'feeInfo.compulsoryInsureAmount',
                headerCellClass: 'table-bg-red',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('交强险应付2', record)
                  goPremiumDetail(record)
                },
              },
            ],
          },
          {
            title: '保养费支出',
            width: 130,
            tooltipList: ['1、根据筛选条件，统计车辆保养费应付总额', '2、保养单状态取：保养完成'],
            dataIndex: 'feeInfo.maintainAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('保养费2', record)
              feeModalRef.value.open(
                { ...queryParam, carId: record.carId, orgIdList: [record.orgId], feeCategory: 6, isFilter: false },
                'assetFee'
              )
            },
          },
          {
            title: '维修费支出',
            width: 130,
            tooltipList: ['1、根据筛选条件，统计车辆维修费总额', '2、维修单状态取：维修完成'],
            dataIndex: 'feeInfo.repairAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('维修费2', record)
              feeModalRef.value.open(
                { ...queryParam, carId: record.carId, orgIdList: [record.orgId], feeCategory: 7, isFilter: false },
                'repairFee'
              )
            },
          },
          {
            title: '年检费支出',
            width: 130,
            tooltipList: ['1、根据筛选条件，统计车辆年检费总额', '2、年检单状态取：年检完成'],
            dataIndex: 'feeInfo.inspectionAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('年检费2', record)
              feeModalRef.value.open(
                { ...queryParam, carId: record.carId, orgIdList: [record.orgId], feeCategory: 8, isFilter: false },
                'inspectionFee'
              )
            },
          },
          {
            title: '车辆借出收入',
            width: 140,
            tooltipList: ['1、根据筛选条件，计算车辆借出收入应收总额', '2、借调单状态取：已借调、借调中、已归还'],
            dataIndex: 'feeInfo.secondOutAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('车辆借出收入2', record)
              feeModalRef.value.open(
                { ...queryParam, carId: record.carId, orgIdList: [record.orgId], feeCategory: 9, isFilter: false },
                'vehicleBorrowFee'
              )
            },
          },
          {
            title: '车辆处置收入',
            width: 140,
            tooltipList: ['统计车辆处置时的出售金额或补贴金额'],
            dataIndex: 'feeInfo.disposalAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('车辆处置收入2', record)
              goDisposalList(record)
            },
          },
          {
            title: '总计',
            width: 100,
            tooltipList: ['总计=车辆借出收入+车辆处置收入-保险费-保养费-维修费-年检费'],
            dataIndex: 'feeInfo.operationTotalAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
    ]
  })

  // 展开表格
  const expandTable = useTable({
    tableLoading: false,
    columns: expandColumns.value,
  })

  const tableColumns = computed(() => {
    return [
      {
        title: '车牌号',
        width: 120,
        dataIndex: 'licenseNo',
        isString: true,
        fixed: 'left',
      },
      {
        title: '车系',
        width: 120,
        dataIndex: 'seriesName',
        isString: true,
      },
      {
        title: '车辆来源',
        width: 110,
        dataIndex: 'carSourceName',
        isString: true,
      },
      {
        title: '车辆当前状态',
        width: 110,
        dataIndex: 'operateStatusName',
        isString: true,
      },
      {
        title: '全生命周期收益情况',
        desc: '(不受核算月份筛选影响)',
        width: 210,
        dataIndex: 'profitFlagName',
        slotName: 'profitFlagName',
        tooltipList: [
          '1、盈利情况不受任何筛选影响，展示最新及最终盈利状态及盈利金额',
          '2、盈利金额=订单营收+车辆借出收入+车辆处置收入+违章代办费-车辆运营费用(保险费支出、保养费支出、维修费支出、年检费支出)-运营成本支出-车辆购入固定支出(包含购置费总额、购置税总额、购车其他支出总额)，计算金额为正数则为已盈利，负数则为未盈利',
        ],
        headerCellClass: 'table-bg-green',
        // children: [
        //   {
        //     title: '车辆购入固定支出',
        //     width: 140,
        //     dataIndex: 'carFixedAmount',
        //     tooltipList: ['车辆购入固定支出=购置费或借入费的总费用+购置税+过户费+运输费+保证金+手续费'],
        //     headerCellClass: 'table-bg-green',
        //     headerCellStyle: {
        //       color: '#25523B',
        //     },
        //   },
        //   {
        //     title: '总盈利',
        //     width: 200,
        //     dataIndex: 'totalProfitAmount',
        //     slotName: 'totalProfitAmount',
        //     tooltipList: ['总盈利=(订单营收+车辆借出收入+车辆处置收入+违章代办费)-车辆保险费支出-车辆保养费支出-车辆维修费支出-车辆年检费支出-运营成本支出'],
        //     headerCellClass: 'table-bg-green',
        //     headerCellStyle: {
        //       color: '#25523B',
        //     },
        //   },
        // ],
      },
      {
        title: '预计收益',
        desc: '(含未结算)',
        width: 140,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-blue',
        children: [
          {
            title: '预计收入',
            width: 110,
            tooltipList: [
              '1、预计收入=结算状态为待结算+已结算的所有收入费项之和',
              '2、预计收入包含的费项为：订单下所有费项、车辆借出收入、车辆处置收入、违章代办总计',
            ],
            dataIndex: 'feeInfo.expectedTotalRevenueAmount',
            headerCellClass: 'table-bg-blue',
            headerCellStyle: {
              color: '#253276',
            },
          },
          {
            title: '预计支出',
            width: 110,
            tooltipList: [
              '1、预计支出=结算状态为待结算+已结算，运营成本支出付款状态为未付款+已付款所有支出费项之和',
              '2、预计支出包含的费项为： 车辆购置费/借入费支出、购置税支出、购车其他支出、保险费支出、保养费支出、维修费支出、年检费支出、报销单支出、付款单支出',
            ],
            dataIndex: 'feeInfo.expectedTotalExpenditureAmount',
            headerCellClass: 'table-bg-blue',
            headerCellStyle: {
              color: '#253276',
            },
          },
          {
            title: '收益总计',
            width: 110,
            tooltipList: ['预计收益总计=预计收入-预计支出'],
            dataIndex: 'feeInfo.expectedTotalProfitAmount',
            headerCellClass: 'table-bg-blue',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '实际收益',
        desc: '(全部已结算)',
        width: 140,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-purple',
        children: [
          {
            title: '实际收入',
            width: 110,
            tooltipList: [
              '1、实际收入=结算状态为已结算，运营成本支出付款状态为已付款所有收入费项之和',
              '2、实际收入包含的费项为：订单下所有费项、车辆借出收入、车辆处置收入、违章代办收入',
            ],
            dataIndex: 'feeInfo.totalRevenueAmount',
            headerCellClass: 'table-bg-purple',
            headerCellStyle: {
              color: '#3A1E4D',
            },
          },
          {
            title: '实际支出',
            width: 110,
            tooltipList: [
              '1、实际支出=结算状态为已结算，运营成本支出付款状态为已付款所有支出费项之和',
              '2、实际支出包含的费项为： 车辆购置费/借入费支出、购置税支出、购车其他支出、保险费支出、保养费支出、维修费支出、年检费支出、报销单支出、付款单支出',
            ],
            dataIndex: 'feeInfo.totalExpenditureAmount',
            headerCellClass: 'table-bg-purple',
            headerCellStyle: {
              color: '#3A1E4D',
            },
          },
          {
            title: '收益总计',
            width: 110,
            tooltipList: ['实际收益总计=实际收入-实际支出'],
            dataIndex: 'feeInfo.totalProfitAmount',
            headerCellClass: 'table-bg-purple',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '订单营收',
        width: 170,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-cyan',
        children: [
          {
            title: '订单收入汇总',
            width: 170,
            isParent: true,
            isChildShow: true,
            isToggle: true,
            toggleStatus: false,
            headerCellClass: 'table-bg-cyan1',
            headerCellStyle: {
              color: '#576F1A',
            },
            children: [
              {
                title: '租金收入',
                width: 110,
                tooltipList: [
                  '1、订单租金：符合筛选条件订单下的车辆租金、手续费、保险费之和，包含续租产生的车辆租金、手续费、保险费',
                  '2、如订单存在换车，则统计的金额为所选车辆在订单使用期间所产生的费用，且订单租金、保险费需平分至每一天计算，手续费则默认归换下车辆',
                  '3、保险费包含基础保险、不计免赔、保险升级以及在系统配置的用车保险费用',
                ],
                dataIndex: 'feeInfo.rentAmount',
                headerCellClass: 'table-bg-cyan1',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('租金收入', record)
                  feeModalRef.value.open(
                    {
                      orgIdList: queryParam.orgIdList,
                      startTime: queryParam.startTime,
                      endTime: queryParam.endTime,
                      carId: record.carId,
                      licenseNo: record.licenseNo,
                      feeCategory: 20,
                      profitFlag: queryParam.profitFlag,
                    },
                    'rentAmount'
                  )
                },
              },
              {
                title: '其他费用收入',
                width: 140,
                tooltipList: [
                  '1、订单中除车辆租金、手续费、保险费以外的剩余所有费项，都为其他费项，包含订单佣金',
                  '2、如订单存在换车，则上门送车费、夜间取车费归属添加费用时正在使用的那辆车，上门取车费、夜间还车费、同城异店还车费、跨城异店还车费归属最后还车车辆',
                ],
                dataIndex: 'feeInfo.orderOtherAmount',
                headerCellClass: 'table-bg-cyan1',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('其他费用收入1', record)
                  feeModalRef.value.open(
                    {
                      orgIdList: queryParam.orgIdList,
                      startTime: queryParam.startTime,
                      endTime: queryParam.endTime,
                      carId: record.carId,
                      licenseNo: record.licenseNo,
                      feeCategory: 21,
                      profitFlag: queryParam.profitFlag,
                    },
                    'otherFeeAmount'
                  )
                },
              },
              {
                title: '渠道线上费用收入',
                width: 110,
                tooltipList: ['1、渠道订单中线上费用总计', '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间所产生的线上费用'],
                dataIndex: 'feeInfo.onlineAmount',
                headerCellClass: 'table-bg-cyan1',
              },
              {
                title: '线下费用收入',
                width: 140,
                tooltipList: ['1、所有订单线下费用总计', '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间所产生的费用'],
                dataIndex: 'feeInfo.offlineAmount',
                headerCellClass: 'table-bg-cyan1',
              },
              {
                title: '收入总计',
                width: 130,
                tooltipList: [
                  '1、订单总收入为所选车辆在订单内的总收入，渠道线上费用收入+线下费用收入',
                  '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间所产生的费用',
                ],
                dataIndex: 'feeInfo.orderTotalAmount',
                headerCellClass: 'table-bg-cyan1',
              },
            ],
          },
          // {
          //   title: '订单重要费项汇总',
          //   headerCellClass: 'table-bg-cyan2',
          //   headerCellStyle: {
          //     color: '#576F1A',
          //   },
          //   children: [
          //     {
          //       title: '续租费',
          //       width: 90,
          //       dataIndex: 'feeInfo.rerentAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '基础保险',
          //       width: 90,
          //       dataIndex: 'feeInfo.orderInsureAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '不计免赔',
          //       width: 110,
          //       tooltipList: computed(() => [
          //         `不计免赔=不计免赔+保险升级+手动配置的费项之和${
          //           deductibleFeeNameEnums.value.length > 0 ? `，手动配置的费项包含：${deductibleFeeNameEnums.value.join('，')}` : ''
          //         }`,
          //       ]),
          //       dataIndex: 'feeInfo.deductibleAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '车损费',
          //       width: 100,
          //       tooltipList: computed(() => [
          //         `车损费=车损费用+配置的相关费用之和${
          //           carDamageFeeNameEnums.value.length > 0 ? `，手动配置的费项包含：${carDamageFeeNameEnums.value.join('，')}` : ''
          //         }`,
          //       ]),
          //       dataIndex: 'feeInfo.carDamageAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //     {
          //       title: '油电费',
          //       width: 100,
          //       tooltipList: computed(() => [
          //         `油电费=油电费用+配置的相关费用之和${
          //           oilFeeNameEnums.value.length > 0 ? `，手动配置的费项包含：${oilFeeNameEnums.value.join('，')}` : ''
          //         }`,
          //       ]),
          //       dataIndex: 'feeInfo.oilAmount',
          //       headerCellClass: 'table-bg-cyan2',
          //     },
          //   ],
          // },
          {
            title: '违章代办收入',
            width: 140,
            tooltipList: [
              '1、违章代办总计=代办服务费-代办真实成本',
              '2、如订单存在换车，则统计的金额为所选车辆在订单时间期间产生违章生成的代办费',
            ],
            dataIndex: 'feeInfo.violationHandleAmount',
            headerCellClass: 'table-bg-cyan',
            headerCellStyle: {
              color: '#576F1A',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('违章代办总计1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId }, 'violationFeeAmount')
            },
          },
          {
            title: '营收总计',
            width: 110,
            tooltipList: ['营收总计=订单总收入+违章代办总计'],
            dataIndex: 'feeInfo.orderRevenueTotalAmount',
            headerCellClass: 'table-bg-cyan',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '运营成本支出',
        width: 150,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-yellow1',
        children: [
          {
            title: '报销单支出',
            width: 130,
            tooltipList: ['1、车辆生成的报销单费用总计', '2、统计报销费用时，时间取费用明细下的费用发生时间，车辆取费用明细下关联的车辆'],
            dataIndex: 'feeInfo.costSellAmount',
            headerCellClass: 'table-bg-yellow1',
            headerCellStyle: {
              color: '#64540E',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('报销单总计1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId, feeCategory: 10 }, 'expenseFeeAmount')
            },
          },
          {
            title: '付款单支出',
            width: 130,
            tooltipList: [
              '1、付款单中关联所选车辆的费用总计',
              '2、统计付款单费用时，时间取费用明细下的费用发生时间，车辆取费用明细下关联的车辆',
            ],
            dataIndex: 'feeInfo.costPayAmount',
            headerCellClass: 'table-bg-yellow1',
            headerCellStyle: {
              color: '#64540E',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('付款单总计1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId, feeCategory: 11 }, 'paymentFeeAmount')
            },
          },
          {
            title: '支出总计',
            width: 110,
            tooltipList: ['支出总计=报销单总计+付款单总计'],
            dataIndex: 'feeInfo.costTotalAmount',
            headerCellClass: 'table-bg-yellow1',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '车辆运营费用',
        width: 150,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-red',
        children: [
          {
            title: '保险费支出',
            width: 190,
            slotName: 'insuranceFee',
            isToggle: true,
            toggleStatus: false,
            tooltipList: [
              '1、商业险、交强险会根据有效期及保险费用，精确计算到每日应付',
              '2、根据筛选条件，统计车辆商业险、交强险保费总额，每日保险金额✖️筛选的时间天数=保险费应付金额',
              '3、取保险单状态：待生效、已生效、已失效、已退保',
              '4、如保险未填写有效期，则不计算，请及时完善保险有效期信息',
            ],
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            children: [
              {
                title: '商业险金额',
                width: 100,
                dataIndex: 'feeInfo.businessInsureAmount',
                headerCellClass: 'table-bg-red',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('商业险应付1', record)
                  goPremiumDetail(record)
                },
              },
              {
                title: '交强险金额',
                width: 100,
                dataIndex: 'feeInfo.compulsoryInsureAmount',
                headerCellClass: 'table-bg-red',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('交强险应付1', record)
                  goPremiumDetail(record)
                },
              },
            ],
          },
          {
            title: '保养费支出',
            width: 130,
            tooltipList: ['1、根据筛选条件，统计车辆保养费应付总额', '2、保养单状态取：待保养、保养中、保养完成'],
            dataIndex: 'feeInfo.maintainAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('保养费1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId, feeCategory: 6 }, 'assetFee')
            },
          },
          {
            title: '维修费支出',
            width: 130,
            tooltipList: ['1、根据筛选条件，统计车辆维修费总额', '2、维修单状态取：待维修、维修中、维修完成'],
            dataIndex: 'feeInfo.repairAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('维修费1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId, feeCategory: 7 }, 'repairFee')
            },
          },
          {
            title: '年检费支出',
            width: 130,
            tooltipList: ['1、根据筛选条件，统计车辆年检费总额', '2、年检单状态取：待年检、年检中、年检完成'],
            dataIndex: 'feeInfo.inspectionAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('年检费1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId, feeCategory: 8 }, 'inspectionFee')
            },
          },
          {
            title: '车辆借出收入',
            width: 140,
            tooltipList: ['1、根据筛选条件，计算车辆借出收入应收总额', '2、借调单状态取：已借调、借调中、已归还'],
            dataIndex: 'feeInfo.secondOutAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('车辆借出收入1', record)
              feeModalRef.value.open({ ...queryParam, carId: record.carId, feeCategory: 9 }, 'vehicleBorrowFee')
            },
          },
          {
            title: '车辆处置收入',
            width: 140,
            tooltipList: ['统计车辆处置时的出售金额或补贴金额'],
            dataIndex: 'feeInfo.disposalAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#8D4A1B',
            },
            isClick: true,
            clickMethod: (record: any) => {
              console.log('车辆处置收入1', record)
              goDisposalList(record)
            },
          },
          {
            title: '总计',
            width: 100,
            tooltipList: ['总计=车辆借出收入+车辆处置收入-保险费-保养费-维修费-年检费'],
            dataIndex: 'feeInfo.operationTotalAmount',
            headerCellClass: 'table-bg-red',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
      {
        title: '车辆购入固定支出',
        width: 170,
        isParent: true,
        isChildShow: true,
        isToggle: true,
        toggleStatus: false,
        align: 'center',
        headerCellClass: 'table-bg-yellow',
        children: [
          {
            title: '车辆购置费/借入费支出',
            width: 210,
            isParent: true,
            isChildShow: true,
            isToggle: true,
            toggleStatus: false,
            headerCellClass: 'table-bg-yellow',
            // tooltipList: ['车辆购置费或借入费的总额+购置补充费总额，不受筛选限制'],
            headerCellStyle: {
              color: '#8F731E',
            },
            children: [
              {
                title: '总额',
                width: 105,
                dataIndex: 'purchaseTotalAmount',
                tooltipList: ['车辆购置费或借入费的总额+购置补充费总额，不受筛选限制'],
                headerCellClass: 'table-bg-yellow',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('车辆购入固定支出 总额', record)
                  goCarDetail(record, 'purchaseTotalAmount')
                },
              },
              {
                title: '应付',
                width: 105,
                tooltipList: [
                  '1、根据筛选的月份，计算车辆每期的购置费或借入费的应付总额',
                  '2、车辆的购置费或借入费未分期，则统一计算在应结时间所属月份',
                ],
                dataIndex: 'feeInfo.purchasePayAmount',
                headerCellClass: 'table-bg-yellow',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('车辆购入固定支出 应付', record)
                  goCarDetail(record, 'purchasePayAmount')
                },
              },
            ],
          },
          {
            title: '购置税支出',
            width: 160,
            isParent: true,
            isChildShow: true,
            isToggle: true,
            toggleStatus: false,
            tooltipList: ['购置税在车辆中不支持分期结算，但支持分期核算，可点击【设置购置税分期】配置分期信息'],
            headerCellClass: 'table-bg-yellow',
            headerCellStyle: {
              color: '#8F731E',
            },
            children: [
              {
                title: '总额',
                width: 90,
                dataIndex: 'purchaseTaxTotalAmount',
                tooltipList: ['车辆购置税总额，不受筛选限制'],
                headerCellClass: 'table-bg-yellow',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('购置税 总额', record)
                  feeModalRef.value.open(
                    {
                      startTime: queryParam.startTime,
                      endTime: queryParam.endTime,
                      carId: record.carId,
                      licenseNo: record.licenseNo,
                      totalAmount: record.purchaseTaxTotalAmount,
                    },
                    'purchaseTax'
                  )
                },
              },
              {
                title: '应付',
                width: 90,
                dataIndex: 'feeInfo.purchaseTaxPayAmount',
                tooltipList: [
                  '1、在筛选时间内，购置税的应付总额',
                  '2、设置分期核算时，根据每期的应结时间统计，未分期则根据费用的应结时间统计一次',
                ],
                headerCellClass: 'table-bg-yellow',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('购置税 应付', record)
                  feeModalRef.value.open(
                    {
                      startTime: queryParam.startTime,
                      endTime: queryParam.endTime,
                      carId: record.carId,
                      licenseNo: record.licenseNo,
                      totalAmount: record.purchaseTaxTotalAmount,
                    },
                    'purchaseTax'
                  )
                },
              },
            ],
          },
          {
            title: '购车其他支出',
            width: 170,
            isParent: true,
            isChildShow: true,
            isToggle: true,
            toggleStatus: false,
            tooltipList: ['购置其他费用=车辆的过户费+运输费+保证金+手续费总额'],
            headerCellClass: 'table-bg-yellow',
            headerCellStyle: {
              color: '#8F731E',
            },
            children: [
              {
                title: '总额',
                width: 90,
                dataIndex: 'purchaseOtherTotalAmount',
                tooltipList: ['购车其他费用总额=车辆的过户费总额+运输费总额+保证金总额+手续费总额，不受筛选限制'],
                headerCellClass: 'table-bg-yellow',
              },
              {
                title: '应付',
                width: 90,
                dataIndex: 'feeInfo.purchaseOtherPayAmount',
                tooltipList: ['根据筛选的月份，计算车辆过户费、运输费、保证金、手续费的应付总额'],
                headerCellClass: 'table-bg-yellow',
                isClick: true,
                clickMethod: (record: any) => {
                  console.log('购车其他费用', record)
                  feeModalRef.value.open({ ...queryParam, carId: record.carId }, 'purchaseOtherFee')
                },
              },
            ],
          },
          {
            title: '总计',
            width: 100,
            dataIndex: 'feeInfo.carFixedTotalPayAmount',
            tooltipList: ['总计=购置费或借入费总额+购置税总额+购车其他费用的总额'],
            headerCellClass: 'table-bg-yellow',
            headerCellStyle: {
              color: '#FF3A3A',
            },
            bodyCellStyle: {
              color: '#FF3A3A',
            },
          },
        ],
      },
    ]
  })
  console.log('tableColumns', tableColumns.value)
  // 表格
  const table = useTable({
    tableLoading: false,
    isFold: true,
    isTableHeaderFold: true,
    columns: tableColumns.value,
  })

  const onSearch = () => {
    loadData(1)
    handleStatisticsData()
  }

  const loadData = (pageNumber?: number) => {
    table.tableLoading = true
    if (pageNumber) {
      queryParam.pageNumber = pageNumber
      table.pagination.page = pageNumber
    } else {
      queryParam.pageNumber = table.pagination.page || 1
      queryParam.pageSize = table.pagination.pageSize
    }

    getsingleCarStatistics(queryParam)
      .then((res: any) => {
        const result = res.result
        table.dataList = result.data.map((item: any) => {
          item.key = item.id
          return item
        })
        table.pagination.pageCount = res.result.total
      })
      .catch(() => {
        table.dataList = []
        table.pagination.pageCount = 0
      })
      .finally(() => {
        table.tableLoading = false
      })
  }

  const scrollbarRef = ref()
  // 滚动位置
  const scrollPosition = ref(0)
  // 处理滚动事件，更新滚动位置
  const onScroll = (ev: Event) => {
    const target = ev.target as HTMLElement | null
    if (target) {
      scrollPosition.value = target.scrollTop
    }
  }

  onMounted(() => {
    handleOrderRevenueTips()
  })

  onActivated(() => {
    if (scrollbarRef.value) {
      scrollbarRef.value.scrollTo({ top: scrollPosition.value })
    }
    loadData()
    handleStatisticsData()
  })
</script>

<style lang="less" scoped>
  .last-update-time {
    color: #86909c;
  }
  .vehicle-accounting {
    padding: 0;

    .content {
      padding: 20px 20px;
    }

    .total-item-value {
      color: #1890ff;
    }
  }

  :deep(.arco-table .arco-table-td) {
    font-size: 13.99px !important;
  }
  .card-wrap {
    margin-bottom: 20px;
  }
  .revenue-summary-card.big-card {
    min-width: 327px;
    width: calc(33% - 10px);
  }
  .canclick {
    text-decoration: underline;
  }
  .canclick:hover {
    cursor: pointer;
    color: #1890ff;
  }
</style>
<style>
  .vehicle-accounting {
    .table-bg-green {
      background-color: #e0f9ec !important;
    }
    .table-bg-yellow {
      background-color: #fff5d8 !important;
    }
    .table-bg-red {
      background-color: #faebe0 !important;
    }
    .table-bg-cyan {
      background-color: #eaf3d5 !important;
    }
    .table-bg-cyan1 {
      background-color: #d0dfa7 !important;
    }
    .table-bg-cyan2 {
      background-color: #dbeeab !important;
    }
    .table-bg-yellow1 {
      background-color: #f6f0d9 !important;
    }
    .table-bg-blue {
      background-color: #ebeefc !important;
    }
    .table-bg-purple {
      background-color: #f1e6f9 !important;
    }
  }
</style>
